partyGames - Monopoly Functions

A simulation package for PHS 7045

Kline DuBose

Introduction

In order to get practice with the Rcpp::Armadillo package and attempt to implement Open MP into the package, there are three new functions and two new S3 methods that I have added to the package

Explanation

Monopoly is one of my favorite games. After the midterm, I knew I wanted to add a simulation for Monopoly to see which spaces are landed on over multiple games. I also found Open MP to be pretty interesting and wanted to get a chance to understand using it better.

Explanation (pt.2)

The board is based on the 2008 Monopoly board.

Monopoly Board

Explanation (pt. 3)

The Chance and Community Chest cards are also from the 2008 US version of the game.

(a) Chance

(b) Community

Figure 1: List of Community Chest cards and Chance cards used.

New Functions

diceRoll

One of the new functions that was added was a dice rolling function that rolls multiple dice and returns a vector representing the dice that were rolled.

# Two six sided dice
diceRoll(6, 2)
[1] 2 1
# Three 100 sided dice
diceRoll(100, 3)
[1] 75 79 46
# Five six sided dice (like yahtzee)
diceRoll(6, 5)
[1] 5 1 6 1 3

monopoly

This function simulates a single-player version of monopoly to and returns a vector of integers that represents how many times each space was landed on during the game.

monopoly(500, 6, 2)
 [1] 14 12 20 14 12  9 20 14 16 13 22 10 16 20  9 12 15 13 16 17 16 18 13 14 17
[26] 11 19 11 19 11 15  5 12 18 18 13 22 18 11  7
monopoly(500, 20, 2)
 [1] 10 19 14 20  7 11 12 12 13 15 16  9 15 16  8 13 22 13 13 13 13 15 13  6 12
[26] 10 13 11 13 17 21 12 11 11  9 10 13 14 13 14

simulateMonopoly

This function simulates multiple single-player versions of the game and returns a list of class “monopoly” where each entry in the list is a vector representing a single game. This doesn’t parallelize the code like I’m hoping it would and is subject to change.

monoGame <- simulateMonopoly(10, 500, 6, 2, 1)
monoGame
[[1]]
 [1] 12 17 15 13 16 19 11  5 13 20 23 10 11 18 17 14 14 21 16 17 14 13  9 19 16
[26] 18 17 18 10 11 16 17 13 16  9 17 13 15 21 10

[[2]]
 [1] 15 20 15 12 18 13 12 17 12 14 32 15 10  5 16 13 13 21 18  9 16 13 13 22 15
[26] 16 17 11 16 11 11 20 19 14 12 13 16 10 15 11

[[3]]
 [1] 14 19  9 12 10 10 20 15 18 10 16 20  8 19 17 14  9 16 14 13 15 22 14 10 13
[26] 21 19 10 12 11 16 15 11 17 16 10 10 12 18 13

[[4]]
 [1] 14 15 17 13 11 13 12 26 14 15 20 13 12 13 10 14 13 13 16 18 15 16 14 14 23
[26] 14 14 17 14 11 15 14 19 10 19 19 16 18  8 14

[[5]]
 [1] 13 14 18  8 18 11 12 21  6 10 27 15 14 10 19 14 13 19 18 18 10 10 14 15 15
[26] 25 16 13 15 14  8 18 24 10 13 10 18 14  9 17

[[6]]
 [1] 15 13 16 15 11 19 11 13 14 18 17 12 16 14 19 11 11 20 15 21 18 12 11 13 16
[26] 13 18 12 13 19 10 16 13 19 10 13 11 19 11 12

[[7]]
 [1] 12 12 15 12 14 13 18  7 17 10 20 17 19 15 12 11 23 13 22 17 11 16 13 20  8
[26] 19 24 18  7 11 15 14 17 18 14 12 11 17 16 15

[[8]]
 [1] 14 14 14 17 10 19 20 13 12 14 16 14 19 11 13 20 22 12 12 11 15 14 14 21 14
[26] 16 14 14 12 21 18 10 19 12 12 23 16 15 14 14

[[9]]
 [1] 11 14 22 16 17  7 11 17 15 18 20 15  8 16 18 16 14 14 14 14 22 17 12 15 18
[26] 13 14 14 14 12 14 23 14 14 15 14 13 10 20 10

[[10]]
 [1] 17 10 13 13 22 16 12 14  7 12 25 19 19 18 13 11 16 10 17 17 22 15 17 15 17
[26] 13 13 18 15 14 12 13 18 11 18 15 12 16 11 16

attr(,"class")
[1] "monopoly" "list"    

summarize.monopoly

This is the S3 method for monopoly class objects. It returns a numeric vector of class “monoSum” that represents how many times each space was landed on over the coure of the various games.

summary.monopoly(monoGame)
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20 
137 148 154 131 147 140 139 148 128 141 216 150 136 139 154 138 148 159 162 155 
 21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40 
158 148 131 164 155 168 166 145 128 135 135 160 167 141 138 146 136 146 143 132 
attr(,"class")
[1] "monoSum" "numeric"

plot.monopoly

This is the S3 method for monopoly and monoSum class objects. It returns a barplot showing which space was landed on the most.

plot.monopoly(monoGame)

Conclusion

This was a fun chance to learn how OpenMP functions and RcppArmadillo as well. Though the parallelization doesn’t always work, I feel like I have a better understanding the requirements to use OpenMP and other libraries used in C++.

Questions

Sources

For the Cards: https://www.monopolyland.com/list-monopoly-chance-community-chest-cards/

For the Board: https://monopoly.fandom.com/wiki/Monopoly_Board

Special Thanks to George Vega Yon and Jonathan Chipman

See also: https://github.com/UofUEpiBio/PHS7045-advanced-programming/tree/main/projects/04-monopoly-game